package com.example.pm.ending.server.controller;

import com.example.pm.ending.server.module.admin.AddNewAdminEntityDTO;
import com.example.pm.ending.server.module.admin.AdminListEntityVO;
import com.example.pm.ending.server.module.admin.UpdateAdminEntityDTO;
import com.example.pm.ending.server.pojo.vo.AdminListVO;
import com.example.pm.ending.server.pojo.vo.AdminStandardVO;
import com.example.pm.ending.server.service.IAdminModuleService;
import com.example.pm.ending.server.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/admins")
@Api(tags = "2.管理员管理模块")
public class AdminModuleController {
    @Autowired
    IAdminModuleService adminModuleService;

    @PostMapping("/add-new")
    @ApiOperation("1.添加管理员信息")
    public JsonResult<Void> addNewAdmin( AddNewAdminEntityDTO addNewAdminEntityDTO ){
        adminModuleService.addNew(addNewAdminEntityDTO);
        return JsonResult.ok();
    }

    @GetMapping("/list")
    @ApiOperation("2.管理员列表展示")
    public JsonResult<List<AdminListEntityVO>> list(){
        List<AdminListEntityVO> list = adminModuleService.list();
        return JsonResult.ok(list);
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("6.根据ID查询管理员详情")
    public JsonResult<AdminStandardVO> getStandardById(
            @PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【根据ID查询管理员详情】的请求，参数：{}", id);
        AdminStandardVO queryResult = adminModuleService.getStandardById(id);
        log.debug("xxxxxxx{}",queryResult);
        return JsonResult.ok(queryResult);
    }

    @ApiOperation("3.管理员信息删除")
    @PostMapping("/{id}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【根据ID删除管理员】的请求，参数：{}", id);
        adminModuleService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("4.管理员信息修改")
    @PostMapping("/{id}/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "管理员ID", required = true, dataType = "long")
    })
    public JsonResult<Void> updateInfoById(@PathVariable Long id, @Valid UpdateAdminEntityDTO updateAdminEntityDTO) {
        log.debug("开始处理【修改管理员详情】的请求，ID：{}，新数据：{}", id, updateAdminEntityDTO);
        adminModuleService.updateInfoById(id, updateAdminEntityDTO);
        return JsonResult.ok();
    }

    @ApiOperation("5.管理员启动")
    @PostMapping("/{id}/enable")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "管理员ID", required = true, dataType = "long"),
    })
    public JsonResult<Void> setEnable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【修改管理员详情】的请求，ID：{}，新数据：{}", id);
        adminModuleService.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("6.管理员禁用")
    @PostMapping("/{id}/disable")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "管理员ID", required = true, dataType = "long"),
    })
    public JsonResult<Void> setDisable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【修改管理员详情】的请求，ID：{}，新数据：{}", id);
        adminModuleService.setDisable(id);
        return JsonResult.ok();
    }





}
